{extend name="public/base" /}

{block name="title"} 后臺首頁-{$title}{/block}

{block name="style"}
{/block}

{block name="main"}

        <!-- Form Row Start -->
        <div class="row">
            <div class="col-md-12">
                <div class="page-box">

                    <ul class="nav nav-tabs" style="margin-bottom:16px;">
                        <li role="presentation" ><a href="/<?=$routeName?>_lst"><?=$config['tableCnName']?>列表</a></li>
                        <li role="presentation" class="active"><a href="/<?=$routeName?>_add">新增<?=$config['tableCnName']?></a></li>
                    </ul>

                    <div class="form-example">

                        <div class="row">
                            <div class="col-md-12 col-sm-12">
                                <div class="form-wrap">
                                    <form id="conform" role="form" action="" method="post">

<?php
     foreach($config['form_fields'] as $k=>$v){
        if(!isset($v['type']) || $v['type'] == '' || $k=='parent_id'){
             continue;
        }
?>
     <?php if($v['type'] == 'text'){ ?>
                                        <div class="form-group">
                                            <label class="control-label" for="pri_name"><?=$v['text']?></label>
                                            <input class="form-control" name="<?=$k?>" placeholder="<?=$v['placeholder']?>" type="text" <?=$v['validate']?>>
                                        </div>

     <?php }elseif($v['type'] == 'password'){?>
                                        <div class="form-group">
                                            <label class="control-label" for="module_name"><?=$v['text']?></label>
                                            <input class="form-control" name="<?=$k?>" placeholder="<?=$v['placeholder']?>"  type="password" <?=$v['validate']?>>
                                        </div>

                                        <div class="form-group">
                                            <label class="control-label" for="module_name"><?=$v['text']?></label>
                                            <input class="form-control" name="re<?=$k?>" recheck="<?=$k?>" placeholder="<?=$v['placeholder']?>"  type="password" <?=$v['validate']?>>
                                        </div>

<?php }elseif($v['type'] == 'textarea'){ ?>
                                        <div class="form-group">
                                            <label class="control-label"><?=$v['text']?>:</label>
                                            <textarea  name="<?=$k?>" placeholder="<?=$v['placeholder']?>" class="form-control" <?=$v['validate']?>></textarea>
                                        </div>

<?php }elseif($v['type'] == 'checkbox'){ ?>

                                        <div class="form-group">
                                            <label class="control-label" for="controller_name"><?=$v['text']?></label>
                                            <div class="col-md-6 col-sm-6">
                                                <?php if(!empty($v['values'])){foreach($v['values'] as $k1=>$v1):?>
                                                <div class="form-group form-checkbox">
                                                    <input type="checkbox" name="<?=$k?>[]" value="<?=$k1?>" id="chk_<?=$k1?>" <?php if($k1==0){echo $v['validate'];}?>>
                                                    <label class="inline control-label" for="chk_<?=$k1?>"><?=$v1?></label>
                                                </div>
                                                <?php endforeach;}?>
                                            </div>
                                        </div>

<?php  }elseif($v['type'] == 'radio'){ ?>
                                        <div class="form-group">
                                            <label class="control-label"><?=$v['text']?>:</label>
                                            <div class="form-gender-valid ">
                                                <div class="row">

                                                    <?php if(!empty($v['values'])){foreach($v['values'] as $k1=>$v1){?>
                                                    <div class="col-md-4">
                                                        <div class="form-group form-radio">
                                                            <input id="radio-<?=$k1?>"  type="radio" name="<?=$k?>" value="<?=$k1?>" <?php if($k1==0){echo $v['validate'];}?> data-parsley-multiple="radio">
                                                            <label for="radio-<?=$k1?>" class="inline control-label"><?=$v1?></label>
                                                        </div>
                                                    </div>
                                                    <?php }} ?>

                                                </div>
                                            </div>
                                        </div>
 <?php }else if($v['type'] == 'select'){ ?>
                                        <div class="form-group">
                                            <label class="control-label"><?=$v['text']?>:</label>
                                            <div id="slWrapper" class="parsley-select wd-250">
                                                <select class="form-control" id="select" <?=$v['validate']?> name="<?=$k?>">
                                                    <option value="0">请选择</option>
                                                <?php if(!empty($v['values'])){foreach($v['values'] as $k1=>$v1):?>
                                                    <option value="<?=$k1?>"><?=$v1?></option>
                                                <?php endforeach;}?>
                                                </select>
                                                <div id="slErrorContainer"></div>
                                            </div>
                                        </div>
              <?php } ?>
         <?php } ?>


                                        <div class="form-group">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-layout-submit">
                                                        <button id="alerts_default" type="submit" class="btn btn-info" >送出</button>
                                                        <button type="reset" class="btn btn-danger">重置</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- End Form Row -->
{/block}

{block name="js"}

<script>
    var demo = $("#conform").Validform({
        tiptype:function(msg,o,cssctl){
            if(o.type == 3) {
                C.alert(msg);
                return false;
            }
        },
        tipSweep:true,
        showAllError:false,

    <?php if(isset($config['has_checkbox']) && $config['has_checkbox'] == 1 ) {?>
        datatype:{
            'need2':function(gets,obj,curform,regxp){
                var need=1,
                    numselected=curform.find("input[name='"+obj.attr("name")+"']:checked").length;
                return  numselected >= need ? true : "請至少選擇"+need+"項！";
            },
        }
    <?php } ?>

    });

</script>
{/block}

